<template>
	<view class="page_bg">
		<image class="logo" src="@/static/vip/img_word.png"></image>
		<view class="tips">
			<view class="tip" @tap="vk.navigateTo('./list')">
				<u-icon name="man-add" size="32"></u-icon>
				<text>我的邀请</text>
			</view>
			<view class="tip" @tap="vk.navigateTo('/pages/login/agreement?type=YQHDGZ')">
				<u-icon name="file-text" size="32"></u-icon>
				<text>活动规则</text>
			</view>
		</view>
		<view class="main">
			<view class="user">
				<u-avatar size="150" :src="vk.getVuex('$user.userInfo.avatar')"></u-avatar>
			</view>
			<image class="title" src="@/static/vip/icon_word02.png"></image>
			<view class="qrcode" v-if="url" @longtap="longtap">
				<vk-data-qrcode ref="qrc" :text="url" :size="376"></vk-data-qrcode>
			</view>
			<view style="font-size: 30rpx">邀请码：{{ invite || "--" }}</view>
		</view>
		<view class="btn" @tap="show = true">链接邀请</view>
		<u-popup v-model="show" mode="bottom" height="650" closeable>
			<view class="share-link-popup">
				<view class="popup-title">链接分享</view>
				<view class="item-title">url链接</view>
				<view class="item-value">{{ url }}</view>
				<view class="item-button">
					<u-button
						:custom-style="{ fontWeight: 'bold', color: '#000000' }"
						@click="copyText(url)"
					>
						复制链接
					</u-button>
				</view>
				<view class="popup-tips">
					. 将链接发送给你要邀请的好友，好友点开链接进入首页并注册，则邀请成功！
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
export default {
	data() {
		return {
			url: "",
			invite: "",

			show: false
		}
	},
	onLoad() {
		this.init()
	},
	methods: {
		init() {
			vk.callFunction({
				url: "client/pub.queryIv",
				title: "获取中..."
			}).then(res => {
				this.invite = res.invite
				this.url = `${res.url}/pages/index/index?inviteCode=${res.invite}`
			})
		},
		copyText(data) {
			vk.pubfn.setClipboardData({
				data: data,
				success: () => {
					vk.toast("复制成功")
				},
				fail: () => {
					vk.toast("复制失败")
				}
			})
		},
		longtap() {
			this.$refs.qrc._saveCode()
		}
	}
}
</script>

<style lang="scss" scoped>
.page_bg {
	min-height: 100vh;
	// #ifdef H5
	min-height: calc(100vh - 88rpx);
	// #endif
	background: url("https://mp-d0bdc000-db91-44a8-852b-e6f607a7ca19.cdn.bspapp.com/cloudstorage/7caea4d1-49d9-45cc-be7d-bcc4c41de15f.png") no-repeat;
	background-size: 100% 100%;
	display: flex;
	flex-direction: column;
	align-items: center;
	position: relative;
}

.logo {
	width: 668rpx;
	height: 268rpx;
	margin: 52rpx 0 12rpx;
}

.tips {
	position: absolute;
	right: 0;
	top: 0;
	.tip {
		border-radius: 60rpx 0 0 60rpx;
		background-color: #ffe778;
		height: 62rpx;
		display: flex;
		align-items: center;
		padding: 0 20rpx 0 26rpx;
		margin-top: 20rpx;
		color: 28rpx;
		.u-icon {
			margin-right: 10rpx;
		}
	}
}

.main {
	width: 750rpx;
	height: 960rpx;
	background: url("https://mp-d0bdc000-db91-44a8-852b-e6f607a7ca19.cdn.bspapp.com/cloudstorage/194e7dae-310b-4414-8429-cc766d4bc0e1.png") no-repeat;
	background-size: 100% 100%;
	display: flex;
	flex-direction: column;
	align-items: center;
	padding-top: 84rpx;
	margin-top: 80rpx;
	.user {
		display: flex;
		flex-direction: column;
		align-items: center;
		font-size: 28rpx;
		margin: -154rpx 0 30rpx;
		.user_name {
			margin-top: 12rpx;
		}
	}
	.title {
		width: 330rpx;
		height: 56rpx;
	}
	.qrcode {
		margin: 30rpx 0 48rpx;
		border: 14rpx solid #fff;
	}
	.text {
		font-size: 38rpx;
		font-weight: 800;
		line-height: 36rpx;
		color: #c16700;
	}
}

.btn {
	border-radius: 44rpx;
	background: linear-gradient(180deg, #fff2dd 0%, #ffdaa5 100%);
	height: 88rpx;
	font-size: 32rpx;
	display: flex;
	justify-content: center;
	align-items: center;
	margin: 20rpx 60rpx 30rpx;
	width: calc(100% - 120rpx);
	font-weight: bold;
}

.share-link-popup {
	padding: 30rpx;
	.popup-title {
		font-weight: bold;
		font-size: 30rpx;
		text-align: center;
	}
	.item-title {
		color: #8c8c8c;
	}
	.item-value {
		padding: 30rpx 26rpx;
		background-color: #efefef;
		margin: 20rpx 0;
		box-sizing: border-box;
		word-break: break-all;
	}
	.popup-tips {
		color: #8c8c8c;
		margin-top: 20rpx;
	}
}
</style>
